package com.closer.server.api;

import com.closer.server.biz.problem.dto.SearchRequest;
import com.closer.server.biz.problem.dto.SubmitRequest;
import com.closer.server.biz.problem.dto.vo.ProblemVO;
import com.closer.server.biz.problem.service.ProblemService;
import com.closer.server.support.common.BaseResponse;
import com.closer.server.support.common.ResultUtils;
import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.*;

/**
 * 题目表 控制层。
 *
 * @author closer
 */
@RestController
@RequestMapping("/problem")
public class ProblemController {

    private final ProblemService problemService;

    public ProblemController(ProblemService problemService) {
        this.problemService = problemService;
    }

    @PostMapping("/search")
    public BaseResponse<Page<ProblemVO>> search(@RequestBody SearchRequest params) {
        var list = problemService.search(params);
        return ResultUtils.success(list);
    }

    @PostMapping("/submit")
    public BaseResponse<Long> doProblem(@RequestBody SubmitRequest params) {
        var result = problemService.doProblem(params);
        return ResultUtils.success(result);
    }

    @GetMapping("/get")
    public BaseResponse<ProblemVO> getProblem(@RequestParam Long id) {
        var result = problemService.get(id);
        return ResultUtils.success(result);
    }
}
